﻿using Microsoft.AspNetCore.Mvc;
using TR.AppService.AppService.RKGL;
using TR.AppService.Dto;
using TR.AppService.Dto.RKGLDto;
using TR.Domain.Entity;
using TR.Domain.Entity.RK;

namespace TR.WebApi.Controllers.RKGLControllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class Wh_Inbill_hController : ControllerBase
    {
        public readonly IWh_Inbill_hAppService iwih;

        public Wh_Inbill_hController(IWh_Inbill_hAppService iwih)
        {
            this.iwih = iwih;
        }

        //入库信息添加
        [HttpPost]
        public async Task<bool> widInsert([FromBody] RKXZDataDto rkxz)
        {
            bool result = await iwih.widInsert(rkxz.wihd, rkxz.widd);
            if (result)
            {
                return true;
            }else
            {
                return false;
            }
        }

        //关联单号分页查询
        [HttpGet]
        public async Task<DtoFenYe<GuanlianJHDH>> GLDHFenYeSelect(int mys,int dqy,string? dqsj,string? jssj, [FromQuery] GLDHTjDto tj)
        {
            return await iwih.GLDHFenYeSelect(mys, dqy, dqsj, jssj, tj);    
        }

        //根据进货订单查询对应的商品
        [HttpGet]
        public async Task<List<JHDHchaHP>> JHDHchahpxx(string buy_code, [FromQuery] HPTj tj)
        {
            return await iwih.JHDHChahp(buy_code, tj);
        }

        //仓库下拉框查询
        [HttpGet]
        public async Task<List<bs_WareHouse>> CKXLKSelect()
        {
            return await iwih.CKXLKSelect();
        }

        //入库管理主表查询
        [HttpGet]
        public async Task<DtoFenYe<RKGL_SelectZB>> RKGL_SelectTjAsync(int mys,int dqy, [FromQuery] RKGLZbTjCx tj)
        {
            return await iwih.RKGLSelect(mys,dqy,tj);
        }

        //批量改变进货状态
        [HttpPut]
        public async Task<bool> StateUpdate(List<int> Bian,char zt)
        {
            return await iwih.updateState(Bian,zt);
        }

        //根据仓库编号查询库位
        [HttpGet]
        public async Task<List<bs_Ware_Area>> SelectArea(string ware_code)
        {
            return await iwih.SelectWare(ware_code);
        }
        
        //批量逻辑删除
        [HttpPut]
        public async Task<bool> RKGLDelete(List<int> isdel)
        {
            return await iwih.RKGLDelete(isdel);
        }

        //单条逻辑删除
        [HttpPut]
        public async Task<bool> RKGLDel(int Bian)
        {
            return await iwih.RKGLDel(Bian);
        }

        //入库管理批量审核
        [HttpPut]
        public async Task<bool> SHUpdate(List<int> Bian,char state,string sureman, string suredate, string remark)
        {
            return await iwih.SHUpdate(Bian,state,sureman,suredate,remark);
        }

        //入库管理批量撤销
        [HttpPut]
        public async Task<bool> CXUpdate(List<int> Bian)
        {
            return await iwih.CXUpdate(Bian);
        }

        //根据编号查询信息
        [HttpGet]
        public async Task<wh_Inbill_h> RKBhSelect(string bh)
        {
            return await iwih.RKBhSelect(bh);
        }

        //编辑入库明细查询
        [HttpGet]
        public async Task<DtoFenYe<RKMXXG>> RKMXSelect(int mys,int dqy,string tj)
        {
            return await iwih.RKMXXGSelect(mys,dqy,tj);
        }

        //入库信息修改
        [HttpPut]
        public async Task<bool> RKUpdate([FromBody] RKXGDataDto rkxx)
        {
            bool jieguo = await iwih.RKUpdate(rkxx.wihd, rkxx.widd);
            if (jieguo)
            {
                return true;
            }
            else
            {
                return false;

            }
        }
    }
}
